# @FileName  : screen.py
# @Time      : 2021/8/27 0014  9:15
# @Author    : LuZhaoHui
# @Software  : PyCharm

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *


# import threading

DiskGMin = 30


def centerDialog(app, dialog):
    screenGeometry = app.primaryScreen().availableGeometry()
    loginGeometry = dialog.geometry()
    x = screenGeometry.x() + (screenGeometry.width() - loginGeometry.width()) / 2
    y = screenGeometry.y() + (screenGeometry.height() - loginGeometry.height()) / 2
    return int(x), int(y)

def setComboBoxState(combo, list):
    combo.setDisabled(False if len(list) > 0 else True)


def setComboBoxHeight(combo, h):
    combo.setStyleSheet("QAbstractItemView::item{height: %dpx;}" % (h))
    combo.setView(QListView())


def showBoxScreenDisk(object):
    showBox(object, "当前打印服务器空间小于 < %dG 请清理项目 ！！！" % (DiskGMin))


def showBox(object, msg, title='提示'):
    QMessageBox.about(object, title, '     %s     ' % (msg))


def showBoxYes(object, msg, title='提示'):
    reply = QMessageBox.question(object,
                                 title,
                                 '     %s     ' % (msg),
                                 QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
    if reply == QMessageBox.Yes:
        return True
    return False


def showLabelImage(area, label, name, self, rotate=0):
    img = QImage()
    img.load(name)
    if rotate > 0:
        transform = QTransform()
        transform.rotate(rotate)
        img = img.transformed(transform)
    if self:
        w = area.width()
        h = area.height()
        img = img.scaled(w, h, Qt.KeepAspectRatio)
    # 显示
    label.setPixmap(QPixmap.fromImage(img))
